package com.gangwangchina.android.contactlib.model;

import java.sql.Blob;
import java.util.HashMap;
import java.util.Map;

import com.gangwangchina.android.contactlib.ContactsInterface;

import android.provider.ContactsContract.CommonDataKinds.Photo;


public class PersonPhoto  extends DataElement{
	public static final String PHOTO = Photo.PHOTO;
	public static final String CONTENT_ITEM_TYPE = Photo.CONTENT_ITEM_TYPE;


	public String im, label;;
	public int type;
	public byte[] blobPhoto;

	/**
	 * Creates a new IMAddress that is not (yet) present in the database
	 * @param im
	 * @return
	 */
	public static PersonPhoto newPersonPhoto(byte[] blobPhoto){
		return new PersonPhoto(blobPhoto);
	}

	/**
	 * Creates an object representation of a IMAddress that is present in the database
	 * @param pcId
	 * @param im
	 * @return
	 */
	public static PersonPhoto recoverPersonPhoto(long pcId, byte[] bs){
		return new PersonPhoto(pcId, bs);
	}

	/**
	 * Creates a new IMAddress
	 * @param pcId the PersonContact the Notes is linked to
	 * @param im
	 */
	private PersonPhoto(long pcId, byte[] blobPhoto){
		this(pcId);
		this.blobPhoto = blobPhoto;
	}

	private PersonPhoto(byte[] blobPhoto){
		this(ContactsInterface.NO_ID, blobPhoto);
	}

	private PersonPhoto(long pcId){
		super(pcId, CONTENT_ITEM_TYPE);
	}



	@Override
	public String toString(){		
		return "";		
	}

	@Override
	public Map<String, Object> getDataColumns() {
		Map<String, Object> datas = new HashMap<String, Object>();
		datas.put(PHOTO, blobPhoto);		
		return datas;
	}

	@Override
	public boolean setProperty(String key, Object value){
		if(key.equals(PHOTO)) blobPhoto = (byte[]) value;
		return true;
	}

	@Override
	public Object getProperty(String key){
		if(key.equals(PHOTO)) return blobPhoto;
		return super.getProperty(key);
	}
}
